﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Routing;
using DynCMS.NET.Core.Entities;
using DynCMS.NET.Core.Interfaces;

namespace DynCMS.NET.Core.Routing
{
    public class CMSRouteConstraint : IRouteConstraint
    {
        IDataRepository<Page> _pageRepo;

        public CMSRouteConstraint(IDataRepository<Page> pageRepo)
        {
            this._pageRepo = pageRepo;
        }

        public bool Match(
            System.Web.HttpContextBase httpContext,
            Route route,
            string parameterName,
            RouteValueDictionary values,
            RouteDirection routeDirection)
        {
            return this._pageRepo.GetAll().Count(p => p.Url == route.Url) > 0;
        }
    }
}